Source for file SC_Pdf.php
Documentation is available at SC_Pdf.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/*----------------------------------------------------------------------
* [概要] Pdfファイルを表示する。(PDFLib必須)
*----------------------------------------------------------------------
function SC_Pdf($width =
595, $height =
842, $fontsize =
10) {
// UTF-8でないとブロック内で改行できない。
$this->block_option =
"encoding=UniJIS-UCS2-H textformat=utf8 fontname=HeiseiMin-W3 textflow=true";
PDF_set_parameter($this->pdf, "license", $this->license_key);
PDF_set_parameter($this->pdf, "pdiwarning", $this->pdiwarning);
PDF_begin_document($this->pdf, NULL, NULL);
$this->page_open =
false;
$this->fontsize =
$fontsize;
$this->arrLines =
array();
$this->arrHeaderColSize =
array();
$this->arrHeaderAlign =
array();
$this->title_enable =
true;
$this->grid_enable =
true;
$this->title_enable =
$flag;
$this->grid_enable =
$flag;
// キー:ブロック名、値:表示テキストのハッシュ配列をセットする。
// キー:ブロック名、値:ファイルパスのハッシュ配列をセットする。
print
("指定したPDFテンプレートは存在しません:".
$pdfpath);
$this->table_left =
$table_left;
$this->arrHeaderColSize =
$arrColSize;
$this->arrHeaderAlign =
$arrAlign;
// ブロックデータの書き込み(closeすると次回新規ページ)
$doc =
pdf_open_pdi($this->pdf, $this->pdfpath, NULL, 0 );
// 既存PDFのドキュメントから指定ページを取得
$page =
pdf_open_pdi_page($this->pdf, $doc, 1, NULL );
PDF_fit_pdi_page($this->pdf, $page, 0, 0, "adjustpage");
for($i =
0;$i <
$max; $i++
) {
foreach($this->arrText[$i] as $key =>
$val) {
$ret =
PDF_fill_textblock($this->pdf, $page, $key, $val, $this->block_option);
for($i =
0;$i <
$max; $i++
) {
foreach($this->arrImage[$i] as $key =>
$val) {
$img =
PDF_load_image($this->pdf, "auto", $val, NULL );
$ret =
PDF_fill_imageblock($this->pdf, $page, $key, $img, NULL);
PDF_close_pdi_page($this->pdf, $page);
PDF_close_pdi($this->pdf, $doc);
PDF_end_page_ext($this->pdf, NULL);
$this->page_open =
false;
PDF_begin_page_ext($this->pdf, $this->width, $this->height, NULL);
PDF_end_page_ext($this->pdf, NULL);
PDF_begin_page_ext($this->pdf, $this->width, $this->height, NULL);
$x =
PDF_get_value($this->pdf, 'pagewidth', 0);
$y =
PDF_get_value($this->pdf, 'pageheight', 0);
// 座標を入れ替えて取得する(左下(0,0)を左上(0,0)に変換)
list
($width, $height) =
$this->getSize();
return array($pdf_x, $pdf_y);
function setTableColor($frame_color =
"000000", $title_color =
"F0F0F0", $line_color =
"D1DEFE", $last_color =
"FDCBFE") {
$this->frame_color =
$frame_color;
$this->title_color =
$title_color;
$this->line_color =
$line_color;
$this->last_color =
$last_color;
function writeGrid($x, $y, $arrCol, $line_max, $last_color_flg =
true) {
for($i =
0; $i <
$max; $i++
) {
if($this->title_enable) {
if(count($this->arrLines) >
0) {
$count =
count($this->arrLines);
for($i =
0; $i <
$count; $i++
) {
$down =
($pos +
1) *
$this->fontsize *
1.5;
$height =
($this->fontsize +
GRID_SPACE) *
$this->arrLines[$i] +
($this->arrLines[$i] -
1);
$pos +=
$this->arrLines[$i];
for($i =
1; $i <=
$line_max; $i++
) {
$down =
$i *
$this->fontsize *
1.5;
$down =
$line_max *
$this->fontsize *
1.5;
$start_col :アンダーライン開始カラム(0:開始カラム)
for($i =
0; $i <
$max; $i++
) {
for($i =
0; $i <
$start_col; $i++
) {
$down =
($line +
1) *
$this->fontsize *
1.5;
$sx =
$x +
$start_x +
GRID_SPACE +
$this->table_left;
list
($page_width, $page_height) =
$this->getSize();
$x =
($page_width -
$width) /
2;
function writeTableCenter($table, $y, $arrCol, $arrAlign, $line_max =
256, $start_no =
1, $last_color_flg =
false) {
foreach($arrCol as $val) {
$x =
$this->getXCenter($width) +
$this->table_left;
list
($ret_x, $ret_y) =
$this->writeTable($table, $x, $y, $arrCol, $arrAlign, $line_max, $start_no, $last_color_flg);
return array($ret_x, $ret_y);
// データの書き込み(closeすると次回新規ページ)
// $start_no:1行目(タイトル)を0とする。
function writeTable($table, $x, $y, $arrCol, $arrAlign, $line_max =
256, $start_no =
1, $last_color_flg =
false) {
$arrRet =
split("\n", $table);
if($line_max >
(count($arrRet) -
$start_no)) {
$line_max =
count($arrRet) -
$start_no;
$this->writeGrid($x, $y, $arrCol, $line_max, $last_color_flg);
// UnicodeエンコーディングとしてUTF-8を設定
PDF_set_parameter($this->pdf, "textformat", "utf8");
if($this->title_enable) {
if(count($this->arrHeaderColSize) >
0 &&
count($this->arrHeaderAlign) >
0 ) {
list
($linecol, $aligncol, $width) =
$this->getTableOption($this->arrHeaderColSize, $this->arrHeaderAlign);
list
($linecol, $aligncol, $width) =
$this->getTableOption($arrCol, $arrAlign);
$option =
"ruler {" .
$linecol .
"} ";
$option.=
"tabalignment {" .
$aligncol .
"} ";
$fontsize =
$this->fontsize;
$option.=
"hortabmethod ruler leading=150% fontname=HeiseiKakuGo-W5 fontsize=$fontsize encoding=UniJIS-UCS2-H";
list
($linecol, $aligncol, $width) =
$this->getTableOption($arrCol, $arrAlign);
$option =
"ruler {" .
$linecol .
"} ";
$option.=
"tabalignment {" .
$aligncol .
"} ";
$option.=
"hortabmethod ruler leading=150% fontname=HeiseiMin-W3 fontsize=$this->fontsize encoding=UniJIS-UCS2-H";
$end_no =
$start_no +
$line_max -
1;
$y +=
$this->fontsize *
1.5;
list
($ret_x, $ret_y) =
$this->writeTableData($table, $x, $y, $width, $start_no, $end_no, $option);
return array($ret_x, $ret_y);
for($i =
0; $i <
$max; $i++
) {
for($i =
0; $i <
$max; $i++
) {
$aligncol.=
$arrAlign[$i] .
" ";
return array($linecol, $aligncol, $width);
function writeTableData($table, $x, $y, $table_width, $start_no, $end_no, $option) {
$arrLine =
split("\n", $table);
for($i =
$start_no; $i <=
$end_no; $i++
) {
$line.=
$arrLine[$i] .
"\n";
$table_height =
$this->fontsize *
1.5 *
($end_no -
$start_no +
1);
$end_y =
$pdf_y -
$table_height;
$tf =
PDF_create_textflow($this->pdf, $enc_table, $option);
PDF_fit_textflow($this->pdf, $tf, $pdf_x, $pdf_y, $pdf_x +
$table_width, $end_y, NULL);
PDF_delete_textflow($this->pdf, $tf);
return array($x, $y +
$table_height);
list
($r, $g, $b) =
sfGetPdfRgb($rgb);
PDF_setcolor($this->pdf, "fillstroke", "rgb", $r, $g, $b, 0);
function writeRect($x, $y, $width, $height, $rgb =
"") {
PDF_rect($this->pdf, $pdf_x,$pdf_y,$width,-
$height);
PDF_rect($this->pdf, $pdf_x,$pdf_y,$width,-
$height);
PDF_rect($this->pdf, $pdf_x+
1,$pdf_y-
1,$width-
2,-
$height+
2);
function writeLine($sx, $sy, $ex, $ey, $rgb =
"000000") {
list
($pdf_sx, $pdf_sy) =
$this->posTopDown($sx, $sy);
list
($pdf_ex, $pdf_ey) =
$this->posTopDown($ex, $ey);
PDF_setlinewidth($this->pdf, 1.0);
PDF_moveto($this->pdf, $pdf_sx, $pdf_sy);
PDF_lineto($this->pdf, $pdf_ex, $pdf_ey);
function output($filekey =
"") {
PDF_end_document($this->pdf, NULL);
$buf =
PDF_get_buffer($this->pdf);
$filename =
$filekey .
date("ymdHis").
".pdf";
header("Content-disposition: attachment; filename=$filename");
header("Content-type: application/octet-stream; name=$filename");
* session_start()を事前に呼び出している場合に出力される以下のヘッダは、
* URL直接呼び出し時にエラーを発生させるので空にしておく。
* Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
PDF_end_document($this->pdf, NULL);
$buf =
PDF_get_buffer($this->pdf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=".
date("YmdHis").
".pdf");
* session_start()を事前に呼び出している場合に出力される以下のヘッダは、
* URL直接呼び出し時にエラーを発生させるので空にしておく。
* Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Documentation generated on Tue, 28 Apr 2009 18:13:38 +0900 by phpDocumentor 1.4.2